a = {
  auctionType: 0,
  close: 0,
  pageNum: 1,
  pageSize: 50,
  queryMore: true,
  rxAuditFlag: 0,
  rxElectronicAllFlag: 0,
  rxElectronicAuditFlag: 0,
  rxHasSendFlag: 0,
  rxOldFlag: 0,
  rxSendFlag: 0,
  rxSuccessflag: 0,
  rxWaitSendflag: 0,
  tradeTag: 0,
  useCheckcode: false,
  useOrderInfo: false,
  errorCheckcode: false,
  action: 'itemlist/SoldQueryAction',
  prePageNo: 8,
  buyerNick: '',
  dateBegin: 0,
  dateEnd: 0,
  logisticsService: '',
  orderStatus: '',
  queryOrder: 'desc',
  rateStatus: '',
  refund: '',
  sellerNick: '',
  tabCode: 'latest3Months'
}
url = '/trade/itemlist/asyncSold.htm?event_submit_do_query=1&_input_charset=utf8'
function getData() {
  var d = ''
  Object.keys(a).forEach(k => {
    if (d) {
      d += '&' + k + '=' + a[k]
    } else {
      d = k + '=' + a[k]
    }
  })
  var xhr = new XMLHttpRequest()
  xhr.open('post', url)
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
  xhr.onreadystatechange = () => {
    if (xhr.status === 200 && xhr.readyState === 4) {
      var res = JSON.parse(xhr.response)
      console.log(res)
      saveData(res)
    }
  }
  xhr.send(d)
}

function saveData(data) {
  var xhr = new XMLHttpRequest()
  xhr.open('post', 'http://127.0.0.1:8080/trade/save')
  xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8')
  xhr.onreadystatechange = () => {
    if (xhr.status === 200 && xhr.readyState === 4) {
      var res = JSON.parse(xhr.response)
      console.log(res)
      if (res.data.code === 1) {
        a.prePageNo = a.pageNum
        a.pageNum += 1
        getData()
      }
    }
  }
  xhr.send(data)
}

getData()
